package me.minecraft.plugin.itemrecycle;

import lg.minecraft.plugin.entityclear.manager.ParserManager;
import me.minecraft.plugin.itemrecycle.command.HelpCommand;
import me.minecraft.plugin.itemrecycle.command.MainCommand;
import me.minecraft.plugin.itemrecycle.command.OpenCommand;
import me.minecraft.plugin.itemrecycle.command.ReloadCommand;
import me.minecraft.plugin.itemrecycle.config.MainConfig;
import me.minecraft.plugin.itemrecycle.util.ComponentUtil;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.PluginCommand;
import org.bukkit.plugin.java.JavaPlugin;

public final class ItemRecycle extends JavaPlugin {

    public static ItemRecycle instance;

    @Override
    public void onLoad() {
        instance = this;
        ParserManager.INSTANCE.registerEntityFilterParser("item_recycle", ComponentUtil::createItemRecycleFilter);
        ParserManager.INSTANCE.registerEntityRemoverParser("item_recycle", ComponentUtil::createItemRecycleRemover);
    }

    @Override
    public void onEnable() {
        MainConfig.INSTANCE.load();
        MainCommand mainCommand = new MainCommand();
        mainCommand.registerSubCommand(new OpenCommand());
        mainCommand.registerSubCommand(new HelpCommand());
        mainCommand.registerSubCommand(new ReloadCommand());
        registerCommand("ItemRecycle", mainCommand);
    }

    private void registerCommand(String name, CommandExecutor executor) {
        PluginCommand command = getCommand(name);
        if (command == null) {
            getLogger().warning("无法注册命令：" + name);
            return;
        }
        command.setExecutor(executor);
    }

}
